//
//  RepairHistoryDetailHeaderCell.m
//  wtshoppingcite
//
//  Created by Baojia-LC on 14/11/13.
//  Copyright (c) 2014年 TW. All rights reserved.
//

#import "RepairHistoryDetailHeaderCell.h"
#import "UIImageView+WebCache.h"
@implementation RepairHistoryDetailHeaderCell


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews{
    
    _titleLabel = [self createLabelWithFrame:CGRectMake(10, 10, 200, 20) text:@"" font:15 textAli:NSTextAlignmentLeft textColor:MAIN_GRAY_COLOR];
    [self.contentView addSubview:_titleLabel];
    
    
    _fontImageView = [[TapImageView alloc] initWithFrame:CGRectMake(60, _titleLabel.bottom+5, SCREEN_WIDTH-60*2, 150)];
    _fontImageView.t_delegate = self;
    _fontImageView.tag = 10000;
   // _fontImageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:_fontImageView];
    
    _preImageView = [[TapImageView alloc] initWithFrame:CGRectMake(60, _fontImageView.bottom+5, SCREEN_WIDTH-60*2, 150)];
    _preImageView.t_delegate = self;
    _preImageView.tag = 10001;
     //_preImageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:_preImageView];
}

-(void)setRepairs:(NSDictionary *)repairs{
    if(_repairs != repairs){
        _repairs = repairs;
        
        NSString* title = [repairs objectForKey:@"descr"];
        _titleLabel.text = title;
        NSString* image1 = [repairs objectForKey:@"imgPath"];
        NSString* preImage = [repairs objectForKey:@"afterImgPath"];
        
        [_fontImageView setImageWithURL:[NSURL URLWithString:image1]];
       
        if([self.state  isEqual: @"3"]){
            NSString* iamge2 = preImage;
            [_preImageView setImageWithURL:[NSURL URLWithString:iamge2]];
            [_preImageView setImageWithURL:[NSURL URLWithString:iamge2] placeholderImage:[UIImage imageNamed:@"imagePath_default"]];
            
            UILabel* label = [self createLabelWithFrame:CGRectMake(30, _fontImageView.top+10, 50, 15) text:@"处理前" font:13 textAli:NSTextAlignmentCenter textColor:[UIColor whiteColor]];
            [label setBackgroundColor:MAIN_BLUE_COLOR];
            
            UILabel* label1 = [self createLabelWithFrame:CGRectMake(30, _preImageView.top+10, 50, 15) text:@"处理后" font:13 textAli:NSTextAlignmentCenter textColor:[UIColor whiteColor]];
            [label1 setBackgroundColor:MAIN_BLUE_COLOR];
            
            [self.contentView addSubview:label];
            [self.contentView addSubview:label1];
            
            [_fontImageView sendSubviewToBack:label];
        }
    }
}

-(void)setComplaint:(NSDictionary *)complaint{
    if(_complaint != complaint){
        _complaint = complaint;
        NSString* title = [complaint objectForKey:@"content"];
        _titleLabel.text = title;
        NSString* image1 = [complaint objectForKey:@"imgPath"];
        NSString* preImage = [complaint objectForKey:@"afterImgPath"];
        [_fontImageView setImageWithURL:[NSURL URLWithString:image1]];
        if([self.state  isEqual: @"3"]){
            NSString* iamge2 = preImage;
            [_preImageView setImageWithURL:[NSURL URLWithString:iamge2]];
            UILabel* label = [self createLabelWithFrame:CGRectMake(30, _fontImageView.top+10, 50, 15) text:@"处理前" font:13 textAli:NSTextAlignmentCenter textColor:[UIColor whiteColor]];
            [label setBackgroundColor:MAIN_BLUE_COLOR];
            
            UILabel* label1 = [self createLabelWithFrame:CGRectMake(30, _preImageView.top+10, 50, 15) text:@"处理后" font:13 textAli:NSTextAlignmentCenter textColor:[UIColor whiteColor]];
            [label1 setBackgroundColor:MAIN_BLUE_COLOR];
            [label1 setBackgroundColor:MAIN_BLUE_COLOR];

            [self.contentView addSubview:label];
            [self.contentView addSubview:label1];
            
            [_fontImageView sendSubviewToBack:label];
        }

    }
    }

#pragma mark - custom delegate
- (void) tappedWithObject:(id)sender
{
    if (self.delegate && [self respondsToSelector:@selector(tappedWithObject:)]) {
        [self.delegate tappedWithObject:sender];
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(UILabel*)createLabelWithFrame:(CGRect)frame text:(NSString*)text font:(int)font textAli:(NSTextAlignment)alig textColor:(UIColor*)tc{
    if(text == nil)
        text = @"";
    UILabel* label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = alig;
    label.textColor = tc;
    label.backgroundColor = [UIColor clearColor];
    return label;
}

@end
